import { registerMapItem, type MapItem } from '@/map-item'
import { entityMapItem, entityMapItemType } from '../base'
import { highLightWaypointFeatures } from './feature'
import { waypointLayer } from './map'
import { waypointIndex } from './geo-index'
import WaypointInfoVue from './WaypointInfo.vue'
import type { Waypoint } from '.'

export function initWaypointMapItem() {
  registerMapItem({
    type: entityMapItemType('Waypoint'),
    typeName: '航路点',
    icon: 'mas-icon-Waypoint',
    getName: (t) => t.id,
    highlight: highLightWaypointFeatures,
    index: {
      enable: () => waypointLayer.visible,
      search: (lng, lat, r) => waypointIndex.search(lng, lat, r)
    },
    infoView: WaypointInfoVue
  })
}

export function waypointMapItem(id: string): MapItem<Waypoint> {
  return entityMapItem('Waypoint', id)
}
